package com.zf.shuashua.channel;

import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.meituan.android.walle.WalleChannelReader;
import com.umeng.analytics.MobclickAgent;
import com.zf.shuashua.BuildConfig;
import com.zf.shuashua.ShuaApplication;
import com.zf.shuashua.api.Store;
import com.zf.shuashua.utils.ToastUtil;

/**
 * copyright：
 *
 * @author：anthui creation date： .
 * @since: 1.0.0
 * @describe:
 */
public class ChannelUtil {


    //这里配置默认渠道
    private static String CHANNEL_DEFAULT = "guanwang";

    /**
     * copyright：
     *
     * @author：anthui creation date： 2020/12/2.
     * @since: 1.0.0
     * @describe: 获取渠道包名
     * <p>
     * 如果是kotlin，直接使用 Context.getChannel()就可
     */

    public static String getChannelName(@NonNull Context context) {
        String channel = WalleChannelReader.getChannel(context);
        if (TextUtils.isEmpty(channel)) {
            if (!BuildConfig.ENABLE_DEBUG) {
                if (Store.getInstance().getNEW_OR_OLDE()) {
                    MobclickAgent.onEvent(ShuaApplication.getContext(), "Channel_error", "新用户");
                } else {
                    MobclickAgent.onEvent(ShuaApplication.getContext(), "Channel_error", "老用户");
                }
            }
            return CHANNEL_DEFAULT;
        }
        return channel;

    }
}
